package com.farewell.service.impl;

import com.farewell.dao.ProductDao;
import com.farewell.pojo.Product;
import com.farewell.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author Farewell
 * @date 2021/3/23
 */
@Service("ProductService")
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductDao productDao;

    @Override
    public List<Product> findAll() {
        List<Product> productList = productDao.findAll();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:ss");
        for (Product product : productList) {
            if (product.getProductStatus()) {
                product.setProductStatusStr("开启");
            }else {
                product.setProductStatusStr("关闭");
            }
            product.setDepartureTimeStr(sdf.format(product.getDepartureTime()));
        }
        return productList;
    }

    @Override
    public void save(Product product) {
        productDao.save(product);
    }

    @Override
    public void delete(String id) {
        productDao.delete(id);
    }

    @Override
    public void update(Product product) {
        productDao.update(product);
    }

    @Override
    public Product findOne(String id) {
        return productDao.findOne(id);
    }

    @Override
    public void updateStatus(String id) {
        productDao.updateStatus(id);
    }
}
